﻿using System;
using QDP.Platform.ObjService;
using QDP.Platform.Services;
using QDP.Platform.Silverlight.Manager;

/// <summary>提供对平台的支持。</summary>
public class Q
{
    /// <summary>获取平台消息监听器</summary>
    public static EventMonitor EventMonitor { get; private set; }
    /// <summary>获取平台组件管理器</summary>
    public static WidgetManager WidgetManager { get; private set; }
    /// <summary>获取平台数据管理器</summary>
    public static DataManager DataManager { get; private set; }
    /// <summary>获取平台工具栏管理器</summary>
    public static ToolbarManager ToolbarManager { get; private set; }
    /// <summary>获取平台界面窗口视图。</summary>
    public static IMasterService MainPage { get; private set; }
    /// <summary>获取平台配置管理器</summary>
    public static ConfigManager ConfigManager { get; private set; }
    /// <summary>获取支撑平台运行的配置信息。</summary>
    public static ConfigObject Config { get { return ConfigManager.Object; } }
    /// <summary>设置平台主容器对象服务；</summary>
    /// <param name="host"></param>
    public static void SetMasterManagerHost(IMasterService host)
    {
        MainPage = host;
    }

    public static void RequestConfig(string url, Action<bool, string> Action)
    {
        ConfigManager.RequestConfig(url, (isSuccess, message) =>
        {
            if (isSuccess)
                WidgetManager = new WidgetManager( Config );
            Action(isSuccess, message);
        });
    }

    private static void InitializePlatform()
    {
        ToolbarManager = new ToolbarManager();
        EventMonitor = new EventMonitor();
        ConfigManager = new ConfigManager();
        DataManager = new DataManager();
    }

    static Q()
    {
        InitializePlatform(); // 初始化平台
    }
}